<div class="fsh-rightPanel">
    <div class="layui-anim layui-anim-upbit">
        <div id="list_form" class="layui-form-item wx-search">
            <div class="layui-inline">
                <label>
                    <input type="text" name="schoolName" placeholder="请输入名称" autocomplete="off" class="layui-input">
                </label>
            </div>
            <button class="layui-btn" id="search">搜索</button>
        </div>
        <table id="list_table" class="layui-hide" lay-filter="mainList"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="font-primary" lay-event="detail">查看</a>
    <a class="font-primary" lay-event="start">开始考试</a>
</script>

<script>
    var parentId;
    layui.use(['layer','table','form'], function () {
        var layer = layui.layer;
        var table = layui.table;
        var form = layui.form;

        var tableObj = table.render({
            elem: '#list_table',
            url: context + '/api/eduTestStudent/list',
            //开启头部工具栏，并为其绑定左侧模板，
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            request: {
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            align: 'center'
            , cols: [[ //表头
                // {type: 'checkbox', fixed: 'left'},
                {field: 'test_id', title: '编号', align: 'center', width: 80},
                {field: 'title_img', title: 'LOGO', align: 'center', width: 150, templet: function (d) {
                        return d.title_img !== undefined ? '<div><img src="' + d.title_img + '" style="height:100px;width:100px;" alt=""/></div>' : '';
                    }
                },
                {field: 'title', title: '标题', align: 'center'},
                {field: 'type', title: '类型', align: 'center', templet: function (d) {
                        return d.type == '0'? '理论':'实践';
                    }},
                {field: 'status', title: '状态', align: 'center', templet: function (d) {
                        switch(d.status){case 0: return '未发布'; case 1: return "已发布"; case 2: return "已结束";default: return "";};
                    }},
                {field: 'schoolCode', title: '学校ID', align: 'center'},
                {field: 'startTime', title: '开始时间', align: 'center', width: 200},
                {field: 'endTime', title: '结束时间', align: 'center', width: 200},
                {field: 'handler', title: '操作', align: 'center', width: 200, toolbar: '#barDemo'}
            ]]
            , page: true
        });
        // 检索
        $("#search").click(function () {
            reloadTable(tableObj);
        });
        //表格头工具栏事件
        table.on('toolbar(mainList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    default: break;
            }
        });

        //表格内部操作按钮监听
        table.on('tool(mainList)', function (obj) { //注：tool是工具条事件名，mainList是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'detail') {
                $.ajax({
                    url: context + '/api/eduTestStudent/getFinishTest?test_id='+data.test_id,
                    type: 'get',
                    success: function(r){
                        r.data.test_id = data.test_id;
                        showDialog({
                            title: '查看详情 - ' + data.title
                            , type: 'get'
                            , template: 'add'
                            , htmlData: r.data
                        });
                    }
                });
            }else if (layEvent === 'start') {
                var index= showConfirm("是否开始考试?", function(){
                    $.ajax({
                        url: context + '/api/eduTestStudent/getStart?test_id='+data.test_id,
                        type: 'get',
                        success: function(r){
                            if(r.success){
                                r.data.test_id = data.test_id;
                                console.log(r.data);
                                showDialog({
                                    title: '进行考试 - ' + data.title
                                    , template: 'startTest'
                                    , saveUrl: context + '/api/eduTestStudent/updatePaper'
                                    , tableObj: tableObj
                                    , htmlData: r.data
                                    , height: 400
                                    , type: "patch"
                                    , dataType: 'json'
                                });
                            }else{
                                showAlert(r.msg||r.errorMsg);
                            }
                            layer.close(index);
                        }
                    });
                });
            }
        });
    });
</script>
<style>
    img.fans-portrait {width: 50px;height: 50px;}
    .fsh-rightPanel .layui-table-body .layui-table-cell {height: 50px;line-height: 50px; }
</style>